import {
	lk_buyer,
	lk_common,
	lk_expert,
	lk_seller,
	lk_manager,
	lk_consumer
} from './myConfig.js';

function requesthttp(method, url, data, header) {
	let headers = Object.assign({
		'content-type': 'application/json',
		'accessToken': uni.getStorageSync('accessToken'),
		'refreshToken': uni.getStorageSync('accessToken')
	}, header)
	return new Promise((resolve, reject) => {
		uni.hideLoading();
		uni.request({
			url,
			method,
			data,
			header: headers,
			success: ({
				data: res
			}) => {
				uni.hideLoading();
				resolve(res);
			},
			fail: function(res) {
				uni.hideLoading();
				uni.showToast({
					title: res.message || '网络响应超时,请稍后再试！',
					icon: 'none'
				});
				reject(res);
			}
		});
	})
}
export const lykApis = {
	/**
	 * 
	 @params id  课程id
	 * 收藏 
	
	**/
	icCollectionCourse: (params) =>
		requesthttp('post', `${lk_buyer}/buyer/passport/member/user/collect`, params),

	/**
	 * 
	 @params
	 记录播放进度
	 "courseId": "课程目录id",
	   "courseSeriesId": "课程id",
	   "playTime": "播放的时间"
	 */
	playbackProgress: (params) => requesthttp('post', `${lk_buyer}/buyer/user/studyRecord/updateWatchRecord`,
		params),
	/**
	 * 
	  @params  
  "courseSeriesId": 课程系列id,
  "evaluateType": "评论类型 0评价 1回复",
  "grade": 分数0到5,
  "pid": 评价传0,
  "userEvaluate": "评论内容"
	 */
	answerComment: (params) => requesthttp('post', `${lk_manager}/courseSeriesBaseEvaluate/save`, params),

	/**
	 * @@param   点赞id评论
	 */
	putfabulous: (id) => requesthttp('get', `${lk_manager}/courseSeriesBaseEvaluate/like/${id}`),

	/**
	 * 
	 @@param courseSeriesId课程id 加入学习 购买
	   
	 */
	buyCoursr: (params) => requesthttp('post', `${lk_buyer}/buyer/user/userCourse/userCourseOrder`, params),
	/**
	 * @@param  courseSeriesId课程id  点赞
	 */
	courseIsGood:(id)=>requesthttp('get', `${lk_expert}/expert/course/courseSeries/courseSeriesLike/${id}`),
	
	/**
	 *关注 专家   idolId专家id   type  0专家1用户
	 */
	followApi:(params)=>requesthttp('post',`${lk_buyer}/buyer/passport/member/user/saveIdol`,params, {
		'content-type': 'application/x-www-form-urlencoded'
	})
}
